class PhoneEntriesController < ApplicationController
  before_filter :authorize
  
  
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @phone_entry_pages, @phone_entries = paginate :phone_entries, :per_page => 10
  end

  def show
    @phone_entry = PhoneEntry.find(params[:id])
  end

  def new
    @phone_entry = PhoneEntry.new
  end

  def create
    @phone_entry = PhoneEntry.new(params[:phone_entry])
    @phone_entry.user_id = session[:user_id]
    if @phone_entry.save
      flash[:notice] = 'PhoneEntry was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @phone_entry = PhoneEntry.find(params[:id])
  end

  def update
    @phone_entry = PhoneEntry.find(params[:id])
    if @phone_entry.update_attributes(params[:phone_entry])
      flash[:notice] = 'PhoneEntry was successfully updated.'
      redirect_to :action => 'list'
    else
      render :action => 'edit'
    end
  end

  def destroy
    PhoneEntry.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
  
  def ajax_create
    render(:layout =>false )
  end
  
  def ajax_edit
    @phone_entry = PhoneEntry.find(params[:id])
    render(:layout =>false )
  end
  
end
